package com.etl.dataflow.executor.listener;

import com.etl.dataflow.executor.communication.SchedulerInterface;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

/**
 * 应用程序启动监听
 *
 * @author dx
 * @since 2022/4/20
 */
@Slf4j
@Component
public class StartupListener implements ApplicationListener<ApplicationStartedEvent> {

    @Override
    public void onApplicationEvent(ApplicationStartedEvent event) {
        // 启动成功后主动向调度中心注册当前执行器
        SchedulerInterface schedulerInterface = (SchedulerInterface) event.getApplicationContext().getBean("schedulerInterface");
        try {
            schedulerInterface.register();
        } catch (Throwable e) {
            e.printStackTrace();
            throw new RuntimeException();
        }
    }
}
